<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="Cache-control" content="no-cache">
    <meta http-equiv="Cache" content="no-cache">
    <meta http-equiv="Cache-Control" content="no-siteapp"/>
    <link rel="shortcut icon" href="/favicon.ico">
    <link href="/css/bootstrap.min.css?v=3.3.5" rel="stylesheet">
    <link href="/css/font-awesome.min.css?v=4.4.0" rel="stylesheet">
    <link href="/css/plugins/bootstrap-table/bootstrap-table.min.css" rel="stylesheet">
    <link href="/css/animate.min.css" rel="stylesheet">
    <link href="/css/style.min.css?v=4.0.0" rel="stylesheet">
    <!-- 搜索样式CSS-Start -->
    <link href="/common/css/searchStyle.css" rel="stylesheet">
    <link href="/css/plugins/jsTree/style.min.css" rel="stylesheet">
    <link href="/css/ui.jqgrid-bootstrap-ui.css?v=4.4.0" rel="stylesheet">
    <link href="/css/ui.jqgrid-bootstrap4.css?v=4.4.0" rel="stylesheet">
    <link href="/css/style.min.css?v=4.0.0" rel="stylesheet">
    <style type="text/css">
        .layui-layer-setwin .layui-layer-close2 {
            right: -10px !important;
            top: 0px !important;
        }

        .layui-layer-self {
            background: transparent !important;
            backgroundColor: transparent !important;
        }
    </style>
</head>

<body class="gray-bg">
<div class="wrapper wrapper-content animated fadeInRight">
    <!-- Panel Other -->
    <div class="ibox float-e-margins">
        <div class="ibox-content">
            <div class="row row-lg">
                <div class="col-sm-12">
                    <!-- Example Events -->
                    <div class="example-wrap">
                        <div class="btn-group hidden-xs" id="exampleTableEventsToolbar" role="group">
                            <form id="seachform">
                                <div class="seach-context">
                                    <label>功能代码 :</label><input id="funid" placeholder="请输入功能代码">
                                    <label>功能名称 :</label><input id="fundesc" placeholder="请输入功能名称">
                                </div>
                                <button id="resetBtn" type="button" class="btn btn-w-m btn-white">重置</button>
                                <button id="addBtn" type="button" power="ADDSYSFUN" class="btn btn-w-m btn-success">新增
                                </button>
                                <button id="searchBtn" type="button" class="btn btn-w-m btn-white">查询</button>
                            </form>
                        </div>
                        <table id="jqGrid">
                        </table>
                    </div>
                </div>
                <!-- End Example Events -->
            </div>
        </div>
    </div>
</div>
<!-- End Panel Other -->
<script src="/js/jquery.min.js?v=2.1.4"></script>
<script src="/js/bootstrap.min.js?v=3.3.5"></script>
<script src="/js/content.min.js?v=1.0.0"></script>
<script src="/js/plugins/bootstrap-table/bootstrap-table.min.js"></script>
<script src="/js/plugins/bootstrap-table/bootstrap-table-mobile.min.js"></script>
<script src="/js/plugins/bootstrap-table/locale/bootstrap-table-zh-CN.min.js"></script>
<script src="/common/pacebox.js"></script>
<script src="/common/bootstrap-table.js"></script>
<script src="/common/form.js"></script>
<script src="/js/plugins/layer-pc/layer.js"></script>
<script src="/js/jquery.cookie.js"></script>
<script src="/common/bootstrap-table-treetable.js"></script>
<script type="text/ecmascript" src="/js/i18n/grid.locale-cn.js"></script>
<!-- This is the Javascript file of jqGrid -->
<script type="text/ecmascript" src="/js/jquery.jqGrid.min.js"></script>
<script type="text/javascript">
    checkPowerAndJump("QRYSYSFUN");
    var parentNameWin = null;
    $(function () {
        $('#resetBtn').click(function () {
            $('#seachform').resetForm();
            loadJqGrid();
        });
        $('#addBtn').click(function () {
            layer.open({
                type: 2,
                title: '新增系统权限',
                shade: 0.8,
                area: ['380px', '80%'],
                content: ['/user/sysfun/add.html', 'auto'], //iframe的url，no代表不显示滚动条
                end: function () { //此处用于演示
                    refreshGrid('jqGrid');
                },
                success: function (layero) {
                    parentNameWin = window[layero.find('iframe')[0]['name']]; //得到iframe页的窗口对象，执行iframe页的方法：
                }
            });
        });


        var config = {
            datagridId: "jqGrid",
            useToken: true,
            url: SSO_URL + 'sy/sysfun/queryFunTree',
            treeGrid: true,
            datatype: "json",
            ExpandColumn: 'funid',
            height: '100%',
            loadComplete: function () {
                var re_records = $("#jqGrid").jqGrid('getGridParam', 'records'); //获取数据总条数
                if (re_records == 0) {
                    $("#jqGrid").append("<tr><td colspan='7' style='text-align: center'>没有找到匹配的记录</td></tr>");
                }
            },
            pager: "false",
            jsonReader: {
                root: "data.result",  //数据模型
                repeatitems: false
            },
            treeReader: {
                level_field: "layid",
                parent_id_field: "parentid",
                leaf_field: "leaf",
                expanded_field: "expand"
            },
            colNames: ['attachid', 'funpath', 'layid', 'botflag', 'useflag', 'displayfun', 'parentid', 'parentName', '功能代码', '功能名称', '是否菜单', '是否使用', '显示菜单权限', '排序值', '操作'],
            "colModel": [
                {
                    "name": "attachid",
                    hidden: true
                },
                {
                    "name": "funpath",
                    hidden: true
                },
                {
                    "name": "layid",
                    hidden: true
                },
                {
                    "name": "botflag",
                    hidden: true
                },
                {
                    "name": "useflag",
                    hidden: true
                }, {
                    "name": "displayfun",
                    hidden: true
                },
                {
                    "name": "parentid",
                    hidden: true
                },
                {
                    "name": "parentName",
                    hidden: true
                },
                {
                    "name": "funid",
                    "index": "funid",
                    "width": 100,
                    key: true,
                    sortable: false
                }, {
                    "name": "fundesc",
                    "index": "fundesc",
                    "width": 100,
                    sortable: false
                }, {
                    "name": "botflagName",
                    "index": "botflagName",
                    "width": 100,
                    sortable: false,
                    formatter: function (value, col, row) {
                        return row.botflag == 0 ? '否' : '是';
                    }
                }, {
                    "name": "useflagName",
                    "index": "useflagName",
                    "width": 100,
                    sortable: false,
                    formatter: function (value, col, row) {
                        return row.useflag == 0 ? '否' : '是';
                    }
                }, {
                    "name": "displayfunName",
                    "index": "displayfunName",
                    "width": 100,
                    sortable: false,
                    formatter: function (value, col, row) {
                        return row.displayfun == 0 ? '否' : '是';
                    }
                }, {
                    "name": "orderval",
                    "index": "orderval",
                    "width": 100,
                    sortable: false
                }, {
                    "name": "op",
                    "index": "op",
                    "width": 100,
                    sortable: false,
                    formatter: function (cellvalue, options, rowObject) {
                        var html = "";
                        if (checkPower("MODSYSFUN")) {
                            html += '<a class="edit" val="' + rowObject.funid + '" href="javascript:void(0)" title="修改">修改</a>&nbsp;&nbsp;&nbsp;';
                        }
                        if (checkPower("DELSYSFUN")) {
                            html += '<a class="del" val="' + rowObject.funid + '"  href="javascript:void(0)" title="删除">删除</a>&nbsp;&nbsp;&nbsp;';
                        }
                        return html;
                    }
                }
            ]
        };
        initJqGrid(config);
        //on方法对动态元素绑定click事件
        $("#jqGrid").on("click", ".edit", function () {
            var rowid = $(this).attr("val");
            $("#jqGrid").jqGrid('setSelection', rowid);
            var row = $('#jqGrid').jqGrid('getRowData', rowid);
            layer.open({
                type: 2,
                title: '修改权限',
                shade: 0.8,
                area: ['380px', '80%'],
                content: ['/user/sysfun/edit.html', 'auto'], //iframe的url，no代表不显示滚动条
                success: function (layers, index) {
                    var body = layer.getChildFrame('body', index);
                    var FormOptions = {};
                    FormOptions['jsonValue'] = row;
                    body.find('#signupForm').initForm(FormOptions);
                    var iframeWin = window[layers.find('iframe')[0]['name']]; //得到iframe页的窗口对象，执行iframe页的方法：iframeWin.method();
                    iframeWin.setInitData(row);
                    parentNameWin = iframeWin;
                }
            });
        });

        $("#jqGrid").on("click", ".del", function () {
            var funid = $(this).attr("val");
            layer.confirm('是否将当前权限删除', {
                btn: ['是', '否'] //按钮
            }, function () {
                var req = {};
                req['reqJSON'] = {
                    type: 'delete',
                    url: SSO_URL + 'sy/sysfun/deleteFun?funid=' + funid,
                    data: {}
                };
                req['successFn'] = function (respData) {
                    layer.msg(respData.message, {icon: 6}, function () {
                    });
                    if (respData.code == SUCCESS_CODE) {
                        loadJqGrid();
                    }
                };
                ajaxRequest(req);
            });
        });
        $('#searchBtn').click(function () {
            loadJqGrid();
        });
    });

    function loadJqGrid() {
        $("#jqGrid").jqGrid('setGridParam', {postData: {funid: $("#funid").val(), fundesc: $("#fundesc").val()}});
        refreshJqGrid('jqGrid');
    }
</script>
</body>
</html>